package com.wiscamp.ninechapters.problems.infrastructure.mappers.types;

import com.wiscamp.ninechapters.problems.infrastructure.po.types.QuestionTypeView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

/**
 * 问题类型仓储对象
 *
 * @author yifeng
 */
@Repository
public interface QuestionTypeViewMapper extends JpaRepository<QuestionTypeView, Long>, JpaSpecificationExecutor<QuestionTypeView> {
    /**
     * 通过代码获取问题类型
     *
     * @param typeCode
     * @return
     */
    @Query(value = "select q from QuestionTypeView q where q.typeCode = :typeCode")
    QuestionTypeView findByTypeCode(String typeCode);

    /**
     * 通过名称获取问题类型列表
     *
     * @param typeName
     * @return
     */
    @Query(value = "select q from QuestionTypeView q where q.typeName = :typeName")
    Collection<QuestionTypeView> findListByTypeName(String typeName);

    @Query(value = "select q from QuestionTypeView q where q.enabled")
    Collection<QuestionTypeView> findListByAvailable();

    /**
     * 分页获取问题类型列表
     *
     * @param spec
     * @param pageable
     * @return
     */
    Page<QuestionTypeView> findAll(Specification<QuestionTypeView> spec, Pageable pageable);

}